
// import * as d3 from "./lib/d3.js";
import * as d3 from "d3";
import {sessionStore} from "./framework/sessionStore.js";
import {defineStatusCard} from "./ux/statusCard.js";

defineStatusCard(d3.selectAll("[data-name=status-card]"), sessionStore);

export const report = {

    status(msg) {
        console.log(`[status] ${msg}`);
        sessionStore.set("status", msg);
    },

    error(err, context) {
        // err is: Error | {resource: string, error: Error|string}
        const error = err?.error ?? err ?? "unexpected error";
        const message = String(error.message ?? error);
        const args = [context ? `[${context}]` : null, err?.resource, error].filter(e => !!e);
        console.error(...args);
        sessionStore.set("error", message);
    },

    reset() {
        sessionStore.save({status: undefined, error: undefined});
    },

};
